﻿using System;
using System.Configuration;
using System.Data.Common;
using System.Data.SqlClient;
using Wangzeran.CodeMaker.Core.DB;

namespace Wangzeran.CodeMaker.PlugIns.DB.SQLServer2005
{
    /// <summary>
    /// SQL Server数据库
    /// </summary>
    public class SQLServerUtility : IDBUtility
    {

        #region IDBUtility 成员

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        private static string m_ConnectionString = null;
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string ConnectionString
        {
            get 
            {
                if (m_ConnectionString == null)
                {
                    m_ConnectionString = 
                        ConfigurationManager.ConnectionStrings["mssql2005"].ConnectionString;
                }
                return m_ConnectionString;
            }
            set
            {
                m_ConnectionString = value;
            }
        }
        /// <summary>
        /// 获取数据库连接对象
        /// </summary>
        /// <returns></returns>
        public DbConnection GetConnection()
        {
            try
            {
                return new SqlConnection(ConnectionString);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void CloseConnection()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
